home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Sample Code Update 01⁄96 / Fragment Tool / Sources / FragmentTool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-20  |  3.9 KB  |  230 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        FragmentTool.c
  3.  
  4.     Contains:    Main event loop and basic keyboard/mouse processing
  5.  
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.                   9/28/95    CW        First release
  13.  
  14. */
  15.  
  16.  
  17.  
  18.  
  19. #ifndef __MEMORY__
  20.     #include <Memory.h>
  21. #endif
  22.  
  23. #ifndef __APPLEEVENTS__
  24.     #include <AppleEvents.h>
  25. #endif
  26.  
  27. #ifndef __DIALOGS__
  28.     #include <Dialogs.h>
  29. #endif
  30.  
  31. #ifndef __DESK__
  32.     #include <Desk.h>
  33. #endif
  34.  
  35. #ifndef __WINDOWS__
  36.     #include <Windows.h>
  37. #endif
  38.  
  39.  
  40. #define    __MAIN__
  41.  
  42.  
  43. #include "FragmentTool.h"
  44.  
  45. #include "Prototypes.h"
  46.  
  47. #if defined(powerc) && !defined(__MWERKS__) // MetroWerks declares "qd" in their runtime
  48.     QDGlobals    qd;
  49. #endif
  50.  
  51.  
  52.  
  53.  
  54. void main ( void );
  55. static void DoKey ( EventRecord*theEvent );
  56. static void DoMouseDown ( EventRecord* theEvent );
  57. static void EventLoop ( void );
  58.  
  59.  
  60.  
  61.  
  62. void main ( void )
  63. {
  64.     MaxApplZone ( );
  65.     
  66.     // We don't use too many more handles, so we onyl need to call
  67.     // MoreMasters a couple of times.
  68.     MoreMasters ( );
  69.     MoreMasters ( );
  70.     
  71.     
  72.     InitToolbox ( );                        // Init toolbox stuff
  73.     InitApplication ( );                    // Init application specific stuff
  74.     EventLoop ( );
  75.     
  76.     
  77.     return;
  78. }
  79.  
  80.  
  81.  
  82. static void EventLoop ( void )
  83. {
  84.     OSErr            theErr;
  85.     EventRecord        theEvent;
  86.     
  87.     
  88.     while ( !gQuit )
  89.     {
  90.         WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );    
  91.         
  92.         switch ( theEvent.what )
  93.         {
  94.             case nullEvent:
  95.             {
  96.                 DialogRef    theDialog;
  97.                 
  98.                 theDialog = FrontWindow ( );
  99.                 if ( GetWindowType ( theDialog ) == kGetInfoWindowType )
  100.                     TEIdle ( ((DialogPeek) theDialog)->textH );
  101.             }
  102.             break;
  103.             
  104.             case mouseDown: 
  105.                 DoMouseDown ( &theEvent );
  106.             break;
  107.             
  108.             case keyDown:
  109.             case autoKey: 
  110.                 DoKey ( &theEvent );
  111.             break;
  112.             
  113.             case activateEvt: 
  114.                 DoActivate ( &theEvent );
  115.             break;
  116.             
  117.             case updateEvt:
  118.                 DoUpdate ( &theEvent );
  119.             break;
  120.             
  121.             case osEvt:
  122.                 if ( (theEvent.message >> 24) & suspendResumeMessage )    /* suspend or resume */
  123.                 {
  124.                     /* Modify the event record to look like an activate/deactivate event */
  125.                     theEvent.modifiers = theEvent.message; /* Copy suspend/resume flag */
  126.                     theEvent.message = (long) FrontWindow ( );    
  127.                     DoActivate ( &theEvent );
  128.                 }
  129.             break;
  130.             
  131.             case kHighLevelEvent:
  132.                 theErr = AEProcessAppleEvent ( &theEvent );
  133.             break;
  134.         }
  135.     }
  136.     
  137.     return;
  138.     
  139. } // EventLoop
  140.  
  141.  
  142.  
  143. static void DoMouseDown ( EventRecord* theEvent )
  144. {
  145.     Point            globalPt = theEvent->where;
  146.     int16            windowPart;
  147.     WindowRef        theWindow;
  148.     long            theMenu;
  149.     
  150.     
  151.     windowPart = FindWindow ( globalPt, &theWindow );
  152.     switch ( windowPart )
  153.     {
  154.         case inMenuBar: 
  155.             theMenu = MenuSelect ( globalPt );
  156.             MenuDispatch ( theMenu );
  157.         break;
  158.         
  159.         case inSysWindow:
  160.             // The SystemClick toolbox routine handles system events
  161.             SystemClick ( theEvent, theWindow );
  162.         break;
  163.         
  164.         case inGoAway: 
  165.             if ( TrackGoAway ( theWindow, theEvent->where ) )
  166.             {
  167.                 // Very easy to implement, and very useful on occasion
  168.                 if ( theEvent->modifiers & optionKey )
  169.                     DoCloseAllDocuments ( );
  170.                 else
  171.                     DoCloseDocument ( theWindow );
  172.             }
  173.         break;
  174.         
  175.         case inDrag:
  176.             DoDragWindow ( theWindow, theEvent );
  177.         break;
  178.  
  179.         case inGrow: 
  180.             DoGrowWindow ( theWindow, theEvent );
  181.         break;
  182.         
  183.         case inContent:
  184.             DoContentClick ( theWindow, theEvent );
  185.         break;
  186.  
  187.         case inZoomIn:
  188.         case inZoomOut: 
  189.             DoZoomWindow ( theWindow, theEvent, windowPart );
  190.         break;
  191.     }
  192.     
  193.     return;
  194.     
  195. } // DoMouseDown
  196.  
  197.  
  198.  
  199. static void DoKey ( EventRecord* theEvent )
  200. {
  201.     char keyPressed = (theEvent->message & charCodeMask);
  202.     
  203.     
  204.     if ( theEvent->modifiers & cmdKey )
  205.     {
  206.         // Command keys get handled by the menu handling routines
  207.         AdjustMenus ( );
  208.         MenuDispatch ( MenuKey ( keyPressed ) );
  209.     }
  210.     else
  211.     {
  212.         // Pass other key strokes to the dialog handling routines
  213.         int16        itemHit;
  214.         WindowRef    theWindow = FrontWindow ( );
  215.         
  216.         if ( IsMovableModal ( theWindow ) )
  217.         {
  218.             if ( DialogSelect ( theEvent, &theWindow, &itemHit ) )
  219.                 DoDialogItemHit ( theWindow, itemHit );
  220.         }
  221.     }
  222.     
  223.     return;
  224.     
  225. } // DoKey
  226.  
  227.  
  228.  
  229.  
  230.